<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="${pageContext.request.contextPath}/resources/assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/assets/css/font-awesome.min.css" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/jslib/ztree-3.5/css/zTreeStyle/zTreeStyle.css" />
</head>
<body>

<ul class="ztree" id="mytreepanel"></ul>
<input id="hid_id" type="hidden" value="${param.id}">


<%@include file="/jsps/inc.jsp" %>
<script type="text/javascript" src="<%=contextPath%>/resources/jslib/ztree-3.5/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="<%=contextPath%>/resources/jslib/ztree-3.5/js/jquery.ztree.excheck-3.5.min.js"></script>
<script type="text/javascript">

	var zTree,roleId;
	function submitForm($pbq)
	{
		var checkedNodes=zTree.getCheckedNodes(true);
		var pids="";
		for(var i=0;i<checkedNodes.length;i++)
		{
			if(i<checkedNodes.length-1)
			{
				pids=pids+checkedNodes[i].id+",";
			}
			else
			{
				pids=pids+checkedNodes[i].id;
			}
		}
		var parameter={
			id:roleId,
			privilegeIds:pids
		};
		$.post('<%=contextPath%>/role/authPrivileges.action',parameter,function(result){
			if(result.success)
			{
				$pbq.msg({
				    msg  : '授权权限成功',
				    type : 'success',
				    time : 3000
				});
			}
			else
			{
				$pbq.alert('保存权限失败');
			}
		})
	}
	$(function(){
		roleId=$("#hid_id").val();
		treeSelector='#mytreepanel';
			//zTree的配置
		var setting={
				data: {
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "pid",
						rootPId: null
					}
				},
				check:{
					enable:true
				}
			};
			$.ajax({
				url:"<%=contextPath%>/role/privileges.action?id="+roleId,
				dataType:'json',
				success:function(data){
					if(data.success)
					{
						zTree=$.fn.zTree.init($(treeSelector),setting,data.data);
					}
					else
						parent.bootStrapQ.alert(data.msg);
				},
				error:function(){
					parent.bootStrapQ.alert('加载数据失败,请重试或联系管理员:)');
				}
			});
	})
</script>
</body>
</html>